package org.facilscrum.persistencia;

import org.facilscrum.beans.Sprintretrospective;
import java.sql.Date; 
import org.facilscrum.beans.*;
import org.facilscrum.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.facilscrum.generales.Mensajeria;
import org.facilscrum.generales.DataGManager;


/**
*
* @author
*/

public class SprintretrospectivePersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
static DataGManager dataGManager;
static List<Sprintretrospective> list;

public SprintretrospectivePersistencia(){
         esMensaje =false;
}



/**
*
* insert()
*/

public static boolean insert (Sprintretrospective sprintretrospective ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into sprintretrospective(idsprint,fecha,bueno,malo,mejorar)  values(?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setInt(1,sprintretrospective.getIdsprint());
        pinsert.setDate(2,sprintretrospective.getFecha());
        pinsert.setString(3,sprintretrospective.getBueno());
        pinsert.setString(4,sprintretrospective.getMalo());
        pinsert.setString(5,sprintretrospective.getMejorar());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Sprintretrospective sprintretrospective ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update sprintretrospective set  idsprint=?, fecha=?, bueno=?, malo=?, mejorar=?  where  idsprintretrospective ='"+sprintretrospective.getIdsprintretrospective()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,sprintretrospective.getIdsprint());
pupdate.setDate(2,sprintretrospective.getFecha());
pupdate.setString(3,sprintretrospective.getBueno());
pupdate.setString(4,sprintretrospective.getMalo());
pupdate.setString(5,sprintretrospective.getMejorar());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  sprintretrospective set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Sprintretrospective sprintretrospective_old , Sprintretrospective sprintretrospective) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update sprintretrospective set  idsprintretrospective=?  where  idsprintretrospective ='"+sprintretrospective_old.getIdsprintretrospective()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(0,sprintretrospective.getIdsprintretrospective());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Sprintretrospective sprintretrospective ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from sprintretrospective  where  idsprintretrospective = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setInt(1,sprintretrospective.getIdsprintretrospective());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from sprintretrospective where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from sprintretrospective  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Sprintretrospective sprintretrospective) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from sprintretrospective where idsprintretrospective='"+sprintretrospective.getIdsprintretrospective()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Sprintretrospective findByPrimaryKey(Sprintretrospective sprintretrospective) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from sprintretrospective where idsprintretrospective='"+sprintretrospective.getIdsprintretrospective()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
   sprint2 =  sprintController.findByPrimaryKey(sprint);
   if (sprint2== null) {
       //no existe registro con ese codigo 
   } else {
   sprint= sprint2;
   sprintretrospective.setSprint(sprint);
     }
            sprintretrospective.setIdsprintretrospective(rs.getInt("idsprintretrospective"));
sprintretrospective.setIdsprint(rs.getInt("idsprint"));
sprintretrospective.setFecha(rs.getDate("fecha"));
sprintretrospective.setBueno(rs.getString("bueno"));
sprintretrospective.setMalo(rs.getString("malo"));
sprintretrospective.setMejorar(rs.getString("mejorar"));
    }
    rs.close();
    psquery.close();
 return sprintretrospective;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByIdsprintretrospective()
*/

public static List<Sprintretrospective> findByIdsprintretrospective(Sprintretrospective sprintretrospective,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from sprintretrospective where idsprintretrospective='"+sprintretrospective.getIdsprintretrospective()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByIdsprint()
*/

public static List<Sprintretrospective> findByIdsprint(Sprintretrospective sprintretrospective,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from sprintretrospective where idsprint='"+sprintretrospective.getIdsprint()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByFecha()
*/

public static List<Sprintretrospective> findByFecha(Sprintretrospective sprintretrospective,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from sprintretrospective where fecha='"+sprintretrospective.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByBueno()
*/

public static List<Sprintretrospective> findByBueno(Sprintretrospective sprintretrospective,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from sprintretrospective where bueno='"+sprintretrospective.getBueno()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByMalo()
*/

public static List<Sprintretrospective> findByMalo(Sprintretrospective sprintretrospective,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from sprintretrospective where malo='"+sprintretrospective.getMalo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByMejorar()
*/

public static List<Sprintretrospective> findByMejorar(Sprintretrospective sprintretrospective,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from sprintretrospective where mejorar='"+sprintretrospective.getMejorar()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Sprintretrospective> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<>();
  String sql = "select * from sprintretrospective";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* Double func(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from sprintretrospective";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from sprintretrospective where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from sprintretrospective";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
     rs.beforeFirst();
     while (rs.next()) {
      x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from sprintretrospective where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return 0;
}


/**
*
* query()
*/

public static List<Sprintretrospective> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
  String sql = "select * from sprintretrospective where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* orderby()
*/

public static List<Sprintretrospective> orderby(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
  String sql = "select * from sprintretrospective order by " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* getListRecords()
*/

public static List<Sprintretrospective> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<>();
  String sql = "select * from sprintretrospective";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "sprintretrospective" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
Sprint sprint = new Sprint();
Sprint sprint2 = new Sprint();
SprintController sprintController = new SprintController();
        Sprintretrospective sprintretrospective2 = new Sprintretrospective(
         rs.getInt("idsprintretrospective"),rs.getInt("idsprint"),rs.getDate("fecha"),rs.getString("bueno"),rs.getString("malo"),rs.getString("mejorar"));
            
    sprint.setIdsprint(rs.getInt("idsprint"));
            
  if(withRelation){
     sprint2 =  sprintController.findByPrimaryKey(sprint);
     if (sprint2== null) {
       //not found records 
     } else {
     sprint= sprint2;
     sprintretrospective2.setSprint(sprint);
       }
   }
       list.add(sprintretrospective2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
 }


}
